﻿/*
Copyright 2009 Matías Fidemraizer (www.matiasfidemraizer.com).

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

using System;

#region "Custom namespace declarations"
using Comkarl;
#endregion

namespace Comkarl.Architecture.Patterns.MVC.Entities
{
    /// <summary>
    /// Represents a view, that is a response which can behave in some way responding to logic or user actions.
    /// </summary>
    /// <typeparam name="TIdentifierName">
    /// The type of the identifier's name.
    /// </typeparam>
    public abstract class View<TIdentifierName> : ControlledEntity<TIdentifierName>, IDisposable
        where TIdentifierName : IEquatable<TIdentifierName>
    {
        #region "Constructors"
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="id">An identifier for the newly created instance.</param>
        public View(ViewIdentifier<TIdentifierName> id)
            : base(id)
        {
        }
        #endregion

        #region "Properties"
        /// <summary>
        /// Gets the current instance's identifier.
        /// </summary>
        new public ViewIdentifier<TIdentifierName> ID
        {
            get
            {
                return (ViewIdentifier<TIdentifierName>)base.ID;
            }
        }
        #endregion

        #region IDisposable Members

        /// <summary>
        /// Releases resources and unregisters current view on the associated controller.
        /// </summary>
        public virtual void Dispose()
        {
            AssociatedController.ViewManager.Remove(this);
        }

        #endregion
    }
}
